<!doctype html>
<html>
<head>
<?php $this->load->view('admin/common_head'); ?>
</head>
<body>
<div class="wrap J_check_wrap">
	<div class="nav">
		<?php
			$tabs = array('index' => '', 'check' => '', 'add' => '');
			$tabs[$this->router->fetch_method()] = 'class="current"';
		?>
		<ul class="cc">
			<li <?php echo $tabs['index']; ?>><a href="<?php echo site_url('admin/link/index'); ?>">链接列表</a></li>
			<li <?php echo $tabs['check']; ?>><a href="<?php echo site_url('admin/link/check'); ?>">链接审核</a></li>
			<li <?php echo $tabs['add']; ?>><a href="<?php echo site_url('admin/link/add'); ?>">+ 添加链接</a></li>
		</ul>
	</div>
	<form class="J_ajaxForm" data-role="list" action="<?php echo site_url('admin/link/do_vieworder'); ?>" method="post" accept-charset="utf-8">
		<div class="table_list">
			<table width="100%">
				<colgroup>
					<col width="60" />
					<col width="60" />
					<col width="200" />
					<col />
					<col width="100" />
					<col width="130" />
					<col width="120" />
					<col width="200" />
				</colgroup>
				<thead>
					<tr>
						<td><label><input type="checkbox" class="J_check_all" data-direction="x" data-checklist="J_check_x">全选</label></td>
						<td>顺序</td>
						<td>站点名称</td>
						<td>站点地址</td>
						<td>站点logo</td>
						<td>添加时间</td>
						<td>
							<select id="J_link_types">
								<option value="">全部</option>
								<option value="newhouse">新房</option>
								<option value="secondhouse">二手</option>
							</select>
						</td>
						<td>操作</td>
					</tr>
				</thead>
				<tbody id="J_link_tr">
				<?php
					foreach($links as $link)
					{
						$type = '';
						$link['type'] == 'all' && $type = '<span class="J_link_newhouse">新房</span><span class="J_link_secondhouse">二手</span>';
						$link['type'] == 'newhouse' && $type = '<span class="J_link_newhouse">新房</span>';
						$link['type'] == 'secondhouse' && $type = '<span class="J_link_secondhouse">二手</span>';
				?>
					<tr>
						<td><input class="J_check" data-xid="J_check_x" data-yid="J_check_y" type="checkbox" name="linkids[]" value="<?php echo $link['linkid']; ?>" /></td>
						<td><input class="input length_0" type="text" name="vieworders[<?php echo $link['linkid']; ?>]" value="<?php echo $link['vieworder']; ?>" /></td>
						<td><?php echo $link['name']; ?></td>
						<td><a href="<?php echo $link['url']; ?>" title="<?php echo $link['descrip']; ?>" target="_blank"><?php echo $link['url']; ?></a></td>
						<td><?php if($link['logo']){ ?><img width="88" height="31" src="<?php echo $link['logo']; ?>" /><?php } ?></td>
						<td><?php echo date('Y-m-d H:i', $link['created']); ?></td>
						<td><div class="cate_link"><?php echo $type; ?></div></td>
						<td>
							<a href="<?php echo site_url('admin/link/edit?linkid='.$link['linkid']); ?>" title="编辑友情链接" class="mr10 J_dialog">[编辑]</a>
							<a href="<?php echo site_url('admin/link/do_del?linkid='.$link['linkid']); ?>" class="mr10 J_ajax_del">[删除]</a>
						</td>
					</tr>
				<?php } ?>
				</tbody>
			</table>
		</div>
		<div class="btn_wrap">
			<div class="btn_wrap_pd">
				<label class="mr20"><input type="checkbox" class="J_check_all" data-direction="y" data-checklist="J_check_y">全选</label>
				<button type="submit" class="btn btn_submit J_ajax_submit_btn">排序</button>
				<button type="button" class="btn btn_success J_ajax_submit_btn" data-action="<?php echo site_url('admin/link/do_check?ifcheck=1'); ?>">审核</button>
				<button type="submit" class="btn">删除</button>
			</div>
		</div>
	</form>
</div>
<?php $this->load->view('admin/common_footer'); ?>
<script type="text/javascript">
Wind.use('dialog',function() {

	//分类筛选
	var link_tr = $('#J_link_tr > tr'),
		link_types = $('#J_link_types');
	link_types.on('change', function(){
		linkFilter(this.value);
	});

	//页面载入筛选
	if(link_types.val()) {
		console.log(link_types.val())
		linkFilter(link_types.val());
	}

	function linkFilter(v){
		link_tr.hide();
		if(v) {
			$('.J_link_'+ v).parents('tr').show();
		}else{
			link_tr.show();
		}
	}
	
	
	//批量删除
	/*
	$('#J_link_del_all').on('click', function(e){
		e.preventDefault();
		if(!$('input.J_check:checked').length) {
			Wind.dialog.alert('请至少选定至一条友情链接');
			return;
		}
		Wind.dialog({
			message	: '确定删除选定的友情链接？', 
			type	: 'confirm',
			onOk	: function() {
				$('form.J_ajaxForm').ajaxSubmit({
					dataType : 'json',
					url		 : 'http://localhost/test/phpwind90rc/admin.php?m=link&c=link&a=doDelete',
					success	 : function(data, statusText, xhr, $form) {
						if(data.state === 'success') {
							var location = window.location;
							location.href = location.pathname + location.search;
						}else{
							Wind.dialog.alert(data.message);
						}
					}
				});
			}
		});
		
	});
	*/
});
</script>
</body>
</html>